//@version=5
// © HancoLab 2025
strategy("[HancoLab] Claude AI가 만든 전략", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.04, slippage=3)

// ==================== 파라미터 설정 ====================

// 볼린저 밴드
bb_length = 20
bb_mult = 2.0

// RSI
rsi_length = 14
rsi_oversold = 35
rsi_overbought = 65

// MACD
macd_fast = 12
macd_slow = 26
macd_signal = 9

// ATR (손절/익절)
atr_length = 14
atr_sl_mult = 1.5
atr_tp_mult = 2.5

// 볼륨 필터
volume_mult = 1.2

// ==================== 지표 계산 ====================

// 볼린저 밴드
[bb_middle, bb_upper, bb_lower] = ta.bb(close, bb_length, bb_mult)

// RSI
rsi = ta.rsi(close, rsi_length)

// MACD
[macd_line, signal_line, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_signal)

// ATR
atr = ta.atr(atr_length)

// 볼륨
avg_volume = ta.sma(volume, 20)
volume_condition = volume > avg_volume * volume_mult

// ==================== 진입 조건 ====================

// 롱 진입 조건
long_bb_condition = close < bb_lower
long_rsi_condition = rsi < rsi_oversold
long_macd_condition = macd_hist > 0 or (macd_hist > macd_hist[1] and macd_hist[1] < macd_hist[2])
long_condition = long_bb_condition and long_rsi_condition and long_macd_condition and volume_condition

// 숏 진입 조건
short_bb_condition = close > bb_upper
short_rsi_condition = rsi > rsi_overbought
short_macd_condition = macd_hist < 0 or (macd_hist < macd_hist[1] and macd_hist[1] > macd_hist[2])
short_condition = short_bb_condition and short_rsi_condition and short_macd_condition and volume_condition

// ==================== 주문 실행 ====================

// 롱 포지션
if long_condition and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    long_sl = close - atr * atr_sl_mult
    long_tp = close + atr * atr_tp_mult
    strategy.exit("Long Exit", "Long", stop=long_sl, limit=long_tp)

// 숏 포지션
if short_condition and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    short_sl = close + atr * atr_sl_mult
    short_tp = close - atr * atr_tp_mult
    strategy.exit("Short Exit", "Short", stop=short_sl, limit=short_tp)

// ==================== 차트 시각화 ====================

// 볼린저 밴드
plot(bb_upper, "BB Upper", color=color.new(color.blue, 70))
plot(bb_middle, "BB Middle", color=color.new(color.gray, 70))
plot(bb_lower, "BB Lower", color=color.new(color.blue, 70))

// 진입 신호
plotshape(long_condition, "Long Signal", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(short_condition, "Short Signal", shape.triangledown, location.abovebar, color.red, size=size.small)

// RSI (별도 패널)
hline(rsi_overbought, "RSI Overbought", color=color.red, linestyle=hline.style_dashed)
hline(rsi_oversold, "RSI Oversold", color=color.green, linestyle=hline.style_dashed)
plot(rsi, "RSI", color=color.purple)